import request from '@/config/axios'

export interface EvalAnnouncementVO {
  id?: number
  planId: number
  title: string
  content: string
  announcementType: number
  publishStatus: number
  isTop: boolean
  topOrder?: number
  publishTime?: Date
  withdrawTime?: Date
  viewCount?: number
  downloadCount?: number
  attachmentUrls?: string
  publisherId?: number
  publisherName?: string
  targetAudience?: string
  effectiveDate?: Date
  expiryDate?: Date
  comments?: string
  createTime?: Date
}

export interface EvalAnnouncementPageReqVO extends PageParam {
  planId?: number
  title?: string
  announcementType?: number
  publishStatus?: number
  isTop?: boolean
  publishTime?: Date[]
  createTime?: Date[]
}

export interface EvalAnnouncementSaveReqVO {
  id?: number
  planId: number
  title: string
  content: string
  announcementType: number
  targetAudience?: string
  effectiveDate?: Date
  expiryDate?: Date
  attachmentUrls?: string
  comments?: string
}

// 查询公告分页
export const getAnnouncementPage = (params: EvalAnnouncementPageReqVO) => {
  return request.get({ url: '/eval/announcement/page', params })
}

// 查询公告详情
export const getAnnouncement = (id: number) => {
  return request.get({ url: '/eval/announcement/get?id=' + id })
}

// 新增公告
export const createAnnouncement = (data: EvalAnnouncementSaveReqVO) => {
  return request.post({ url: '/eval/announcement/create', data })
}

// 修改公告
export const updateAnnouncement = (data: EvalAnnouncementSaveReqVO) => {
  return request.put({ url: '/eval/announcement/update', data })
}

// 删除公告
export const deleteAnnouncement = (id: number) => {
  return request.delete({ url: '/eval/announcement/delete?id=' + id })
}

// 导出公告 Excel
export const exportAnnouncement = (params: EvalAnnouncementPageReqVO) => {
  return request.download({ url: '/eval/announcement/export-excel', params })
}

// 发布公告
export const publishAnnouncement = (id: number) => {
  return request.put({ url: '/eval/announcement/publish?id=' + id })
}

// 撤回公告
export const withdrawAnnouncement = (id: number) => {
  return request.put({ url: '/eval/announcement/withdraw?id=' + id })
}

// 置顶公告
export const topAnnouncement = (id: number, topOrder: number) => {
  return request.put({ url: '/eval/announcement/top?id=' + id + '&topOrder=' + topOrder })
}

// 取消置顶
export const cancelTopAnnouncement = (id: number) => {
  return request.put({ url: '/eval/announcement/cancel-top?id=' + id })
}

// 获取公告统计
export const getAnnouncementStatistics = (planId?: number) => {
  const params = planId ? { planId } : {}
  return request.get({ url: '/eval/announcement/statistics', params })
}
